package com.yang.limit.config;


import com.yang.limit.aspect.RequestLimitAspect;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import javax.annotation.PostConstruct;


/**
 * 接口限流自动配置类
 */
@Configuration
@EnableAspectJAutoProxy
public class RequestLimitAutoConfiguration {

    @Bean
    public RequestLimitAspect requestLimitAspect(){
        return new RequestLimitAspect();
    }


    /**
     * 生成令牌线程池
     */
    @Bean(name = "tokenBucketThreadPoolScheduler")
    public ThreadPoolTaskScheduler tokenPushThreadConfig() {
        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
        scheduler.setPoolSize(1);
        scheduler.setThreadNamePrefix("令牌桶算法线程");
        return scheduler;
    }

    /**
     * 漏桶滴水线程池
     */
    @Bean(name = "leakyBucketThreadPoolTaskScheduler")
    public ThreadPoolTaskScheduler leakyBucketPopThreadConfig() {
        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
        scheduler.setPoolSize(1);
        scheduler.setThreadNamePrefix("漏桶限流算法线程");
        return scheduler;
    }
}
